<?php


namespace App\Remote\Rms;

use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Request as RequestAlias;

class RmsUserRemote extends BaseRmsRemote
{


    /**
     * 获取rms用户基础信息
     *
     * @param array $userIds
     * @param array $fields
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getRmsUserByIds(array $userIds, array $fields = [], bool $isThrow = true)
    {
        if (!$userIds) {
            return [];
        }

        try {
            return self::customCacheRequest(
                "api/internal/user/getUserInfoByIds",
                "get",
                ["userIds" => implode(",", $userIds), 'fields' => $fields],
                null,
                5 * 60
            );
        } catch (\Exception $e) {
            if ($isThrow) {
                throw $e;
            } else {
                return '';
            }
        }
    }

    /**
     * 获取职位员工列表
     *
     * @param int $roleId
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getRoleUserLists(int $roleId)
    {
        return self::customRequest(
            "api/internal/user/getRoleUserLists",
            "get",
            ["roleId" => $roleId]
        );
    }

    /**
     * @param int $roleId
     * @param int $userId
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function isRoleUser(int $roleId, int $userId)
    {
        return self::customRequest(
            "api/internal/user/isRoleUser",
            "get",
            ["roleId" => $roleId, "userId" => $userId]
        );
    }


    /**
     * 消息中心所有用户 ID
     *
     * @param int $lastId
     * @param int $type
     * @param string $cityCode
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getNotifyAllUserList(int $lastId, int $type, string $cityCode = '')
    {
        return self::customRequest(
            "api/internal/user/getNotifyAllUserLists",
            "get",
            [
                'lastId'   => $lastId,
                'type'     => $type,
                'cityCode' => $cityCode
            ]
        );
    }

    /**
     * 员工档案缺失门店,员工 列表
     *
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getProblemShopStaffList()
    {
        return self::customRequest(
            "api/internal/user/getProblemShopStaffList",
            "get"
        );
    }


    /**
     * 消息中心获取所有店长的 userId
     *
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getShopManagerUserLists()
    {
        return self::customRequest(
            "api/internal/user/getShopManagerUserLists",
            "get"
        );
    }

    /**
     * 通过shopId 获得对应店长的 userId
     *
     * @param array $shopIds 二选一
     * @param array $shopCodes
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getShopManagerUserByShopId(
        array $shopIds,
        array $shopCodes = [],
        bool $filterWebUser = false
    ) {
        return self::customRequest(
            "api/internal/user/getShopManagerUserByShopId",
            "get",
            ['shopIds' => $shopIds, 'shopCodes' => $shopCodes, 'filterWebUser' => (int)$filterWebUser]
        );
    }

    /**
     * 获取用户信息 & 当前门店权限
     *
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getUserinfoWithAuth()
    {
        return self::customCacheRequest(
            "api/merchant/user/getUserinfoWithShopAuth",
            RequestAlias::METHOD_GET,
            null,
            null,
            60
        );
    }

    /**
     * 查询开发经理列表
     *
     * @param string $username
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getManagerList(string $username)
    {
        return self::customCacheRequest(
            "api/internal/user/getWebUserList",
            "get",
            ["username" => $username],
            null,
            10 * 60
        );
    }

    /**
     * 查询开发经理列表
     *
     * @param string $username
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getSiteTaskHandlerList(string $username)
    {
        return self::customCacheRequest(
            "api/internal/user/getSiteTaskHandlerList",
            "get",
            ["username" => $username],
            null,
            10 * 60
        );
    }

    /**
     * 获得未开通网商的用户ID
     *
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getNoPowerWalletByProvince(int $provinceCode = 310000)
    {
        return self::customCacheRequest(
            "api/internal/user/getNoPowerWalletByProvince",
            RequestAlias::METHOD_GET,
            ['provinceCode' => $provinceCode]
        );
    }


    /**
     * 查询飞书用户信息
     *
     * @param array $userIds
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getFsUserListByIds(array $userIds)
    {
        return self::customCacheRequest(
            "api/internal/fsUser/getUserListByIds",
            "get",
            ["userIds" => $userIds],
            null,
            10 * 60
        );
    }

    /**
     * @param array $mobiles
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getUserByMobiles(array $mobiles)
    {
        return self::customCacheRequest(
            "api/internal/user/getUserInfoByMobiles?" . http_build_query([
                "mobiles" => implode(",", $mobiles)
            ]),
            "get"
        );
    }

    /**
     * @param array $mobiles
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function addUserActionLog(string $unionid, string $shopId)
    {
        return self::customCacheRequest(
            "api/internal/customer/addCustomerActionLog",
            "post", [
                'unionId' => $unionid,
                'shopId'  => $shopId
            ]
        );
    }

    /**
     * @param $userId
     * @param string $userIp
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getMerchantLoginJwt($userId, string $userIp)
    {
        return self::customCacheRequest(
            "api/internal/user/getMerchantLoginJwt",
            "post", [
                'userId' => $userId,
                'userIp' => $userIp
            ]
        );
    }

    /**
     * 模糊查询用户名称
     * @param string $userName
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getRmsUserIdByUserName(string $userName)
    {
        return self::customCacheRequest(
            'api/internal/user/getRmsUserIdByUserName',
            'get',
            [
                'userName' => $userName,
            ],
            null,
            10 * 60
        );
    }

    /**
     * 通过unionId获取用户信息
     * @param array $unionids
     * @return mixed|void
     * @throws GuzzleException
     */
    public static function getCustomerPlatformUsers(array $unionids)
    {
        return self::customCacheRequest(
            'api/internal/customer/getCustomerPlatformUsers',
            'get',
            [
                'unionIds' => implode(',', $unionids),
            ],
            null,
            10 * 60
        );
    }

    public static function usersInShops(array $shopIds)
    {
        return self::customCacheRequest(
            'api/internal/user/usersInShops',
            'get',
            [
                'shopIds' => $shopIds,
            ],
            null,
            10 * 60
        );
    }

    /**
     * @return mixed|null
     * @throws GuzzleException
     */
    public static function decodeJwt()
    {
        return self::customCacheRequest(
            "api/internal/user/decodeJwt",
            "post"
        );
    }

    /**
     * @param array $userList
     * @return mixed|null
     * @throws GuzzleException
     */
    public static function importSupplierCruiseStaff(array $userList)
    {
        return self::customCacheRequest(
            'api/internal/user/importSupplierCruiseStaff',
            'post',
            [
                'userList' => $userList
            ],
        );
    }


}
